package com.boot.project.controller;

import com.boot.project.domain.CourtDO;
import com.boot.project.domain.CourtTimeDO;
import com.boot.project.service.CourtService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;


/**
 * 订场的controller
 */
@RequestMapping("/court")
@RestController
public class CourtController {
    @Autowired
    private CourtService courtService;

    // 当前端界面点击日期的时候，查询出该日期的所有球场信息
    @GetMapping("/getCourt")
    public List<CourtDO> getCourt(@RequestParam String dateTime) {
        return courtService.getCourt(dateTime);
    }

    // 根据球场ID获取球场的时间段信息
    @GetMapping("/getCourtTime")
    public List<CourtTimeDO> getCourtTime(@RequestParam Long courtId) {
        return courtService.getCourtTime(courtId);
    }

    // 在某个日期新增球场接口
    @PostMapping("/saveCourt")
    public Map<String, Object> saveCourt(@RequestBody CourtDO courtDO) {
        return courtService.saveCourt(courtDO);
    }

    // 给某个球场新增时间段接口
    @PostMapping("/saveCourtTime")
    public Map<String, Object> saveCourtTime(@RequestBody CourtTimeDO courtTimeDO) {
        return courtService.saveCourtTime(courtTimeDO);
    }

    // 修改某个球场信息接口
    @PostMapping("/updateCourt")
    public Map<String, Object> updateCourt(@RequestBody CourtDO courtDO) {
        return courtService.updateCourt(courtDO);
    }

    // 修改某球场某条时间段接口
    @PostMapping("/updateCourtTime")
    public Map<String, Object> updateCourtTime(@RequestBody CourtTimeDO courtTimeDO) {
        return courtService.updateCourtTime(courtTimeDO);
    }

    // 删除某球场的接口
    @DeleteMapping("/deleteCourt")
    public Map<String, Object> deleteCourt(@RequestParam Long id) {
        return courtService.deleteCourt(id);
    }

    // 删除某个时间段的接口
    @DeleteMapping("/deleteCourtTime")
    public Map<String, Object> deleteCourtTime(@RequestParam Long id) {
        return courtService.deleteCourtTime(id);
    }

    // 当订场支付了之后，更新该时间段的状态
    @GetMapping("/changeStatus")
    public Map<String, Object> changeStatus(@RequestParam Long courtTimeId) {
        return courtService.changeStatus(courtTimeId);
    }

    @GetMapping("/getStatus")
    public Map<String, Object> getStatus(Long courtTimeId) {
        Map<String, Object> result = new HashMap<>();
        result.put("status", courtService.getStatus(courtTimeId));
        return result;
    }

    // 修改某个球场时间段状态为0，即正常状态
    @GetMapping("/changeStatusNormal")
    public Map<String, Object> changeStatusNormal(@RequestParam Long courtTimeId){
        return courtService.changeStatusNormal(courtTimeId);
    }
}
